package com.google.code.openperfmon.service;

import java.util.ArrayList;
import java.util.List;

import com.google.code.openperfmon.Status;
import com.google.code.openperfmon.domain.OutputVariable;

public class ExecutionContext {
	private List<String> inputs;
	private List<OutputVariable> output;
	private String host;
	private Status status;
	private String message;
	private boolean success;
	
	public String getHost() {
		return host;
	}
	public void setHost(String host) {
		this.host = host;
	}
	public Status getStatus() {
		return status;
	}
	public void setStatus(Status status) {
		this.status = status;
	}
	public List<String> getInputs() {
		return inputs;
	}
	public void setInputs(List<String> inputs) {
		this.inputs = inputs;
	}
	public void addInput(String inp) {
		if (inputs == null) inputs = new ArrayList<String>();
		inputs.add(inp);
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	
	public void setOutput(String var, Double value) {
		if (output == null) resetOutput();
        for (OutputVariable out : output) {
            if (var.equals(out.getVarName()) && out.getKey() == null) {
                out.setValue(value);
                return;
            }
        }
        OutputVariable out = new OutputVariable(var, value);
        output.add(out);
    }
   
	public void setOutput(String var, String key, Double value) {
		if (output == null) resetOutput();
        for (OutputVariable out : output) {
            if (var.equals(out.getVarName()) && key.equals(out.getKey())) {
                out.setValue(value);
                return;
            }
        }
        OutputVariable out = new OutputVariable(var, key, value);
        output.add(out);
    }
   
	public void resetOutput() {
        output = new ArrayList<OutputVariable>(10);
    }

    public List<OutputVariable> getOutput() {
        return output;
    }
    
    public Double getSingleOutput(String var) {
    	if (output == null) return null;
    	for (OutputVariable out : output) {
    		if (var.equals(out.getVarName())) return out.getValue();
    	}
    	return null;
    }
    
    public Double getOutputByKey(String var, String key) {
    	if (output == null) return null;
    	for (OutputVariable out : output) {
    		if (var.equals(out.getVarName()) && key.equals(out.getKey())) return out.getValue();
    	}
    	return null;
    }
	public boolean isSuccess() {
		return success;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}
}
